package com.weikuang.fareast.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.weikuang.fareast.R;
import com.weikuang.fareast.adapter.NotAdapter;
import com.weikuang.fareast.bean.UsualGoodsBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.dlc.commonlibrary.ui.widget.TitleBar;
import cn.dlc.commonlibrary.utils.rv_tool.RecyclerViewUtil;

public class NotActivity extends BaseActivity {
    @BindView(R.id.mTitleBar)
    TitleBar mTitleBar;
    @BindView(R.id.number)
    TextView edNumber;
    @BindView(R.id.btn_goods_sure)
    Button btnGoodsSure;
    @BindView(R.id.recycler)
    RecyclerView mRecyclerView;


    private NotAdapter mNotAdapter;
    UsualGoodsBean.DataBean mNotdata = null;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_not;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        UsualGoodsBean data = (UsualGoodsBean)getIntent().getSerializableExtra("data");
        InitRecyclerView();
        if (data != null){
            mNotAdapter.setNewData(data.data);
        }
        btnGoodsSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent i = new Intent();
                i.putExtra("data",mNotdata);
                setResult(5, i);
                finish();

            }
        });
    }

    private void InitRecyclerView() {
        mNotAdapter = new NotAdapter();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewUtil.setDefaultDivider(mRecyclerView, linearLayoutManager);
        mRecyclerView.setAdapter(mNotAdapter);

        mNotAdapter.setOnItemClickListener(new NotAdapter.OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, UsualGoodsBean.DataBean data, int position) {
                edNumber.setText(data.title);
                mNotdata = data;
            }
        });

    }

//    private void getUser() {
//        String keyword = edNumber.getText().toString();
//        MainHttp.get().gethotelNew( keyword)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .compose(bindUntilEvent(ActivityEvent.DESTROY))
//                .subscribe(new OkObserver<HotelBean>() {
//                    @Override
//                    public void onSuccess(HotelBean hotelBean) {
//                        showOneToast(hotelBean.msg);
//                        mHotelAdapter.setNewData(hotelBean.data);
//                    }
//
//                    @Override
//                    public void onFailure(String message, Throwable tr) {
//                        ToastUtil.show(getActivity(), message);
//                    }
//                });
//    }
}
